﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using F_SER.DAL;
using F_SER.Module;

namespace F_SER
{
    // 注意: 使用“重构”菜单上的“重命名”命令，可以同时更改代码、svc 和配置文件中的类名“Service1”。
    [ServiceBehavior(IncludeExceptionDetailInFaults = true)]
    public class Service1 : IService1
    {

        /// <summary>
        /// 验证登陆返回权限表
        /// </summary>
        /// <param name="xml">xml.toString()</param>
        /// <param name="ap_set">返回dateset</param>
        /// <returns></returns>
        public string f_charge(string xml, ref DataSet ap_set)
        {
            try
            {
                SqlHelper sqlhelper = new SqlHelper();
                SqlParameter[] para = new SqlParameter[]
					{
						new SqlParameter("AS_IN", xml),
						new SqlParameter("AS_OUT", SqlDbType.VarChar, 1024 ), //输出参数
						new SqlParameter("AI_DO",  SqlDbType.Int), 
					};
                para[0].Direction = ParameterDirection.Input;
                para[1].Direction = ParameterDirection.Output;
                para[2].Direction = ParameterDirection.Output;

                ap_set = sqlhelper.RunProcDataSet("ZWP_STORM", para);
                return para[1].Value.ToString();
            }
            catch (Exception)
            {

                throw;
            }

        }
        /// <summary>
        /// 执行存储过程返回out值
        /// </summary>
        /// <param name="ProName"></param>
        /// <param name="xml"></param>
        /// <returns></returns>
        public string GetOutValue(string ProName, string xml)
        {
            try
            {
                SqlHelper sqlhelper = new SqlHelper();
                SqlParameter[] para = new SqlParameter[]
					{
						new SqlParameter("AS_IN", xml),
						new SqlParameter("AS_OUT", SqlDbType.VarChar, 100 ), //输出参数
					};
                para[0].Direction = ParameterDirection.Input;
                para[1].Direction = ParameterDirection.Output;
                sqlhelper.RunProc(ProName, para);
                return para[1].Value.ToString();
            }
            catch (Exception)
            {

                throw;
            }

        }

        /// <summary>
        /// 数据库同步更新传过来的DataSet
        /// </summary>
        /// <param name="ap_set">传入的dataSet数据集</param>
        /// <param name="ProName">存储过程名字</param>
        /// <param name="xml">xml字符串</param>
        /// <returns>返回的结果</returns>
        public string f_save(DataSet ap_set, string ProName, string xml)
        {
            try
            {
                SqlParameter[] para = new SqlParameter[]
					{
						new SqlParameter("AS_IN", xml),
						new SqlParameter("AS_OUT", SqlDbType.VarChar, 1024 ), //输出参数
					};
                para[0].Direction = ParameterDirection.Input;
                para[1].Direction = ParameterDirection.Output;
                return new SqlHelper().f_save(ap_set, ProName, para);
            }
            catch (Exception)
            {

                throw;
            }

        }

        /// <summary>
        /// 数据库同步更新传过来的DataSet
        /// </summary>
        /// <param name="ap_set">传入的dataSet数据集</param>
        /// <param name="ProName">存储过程名字</param>
        /// <param name="xml">xml字符串</param>
        /// <returns>返回的结果</returns>
        public string f_saveTable(DataTable ap_set, string ProName, string xml)
        {
            try
            {
                SqlParameter[] para = new SqlParameter[]
					{
						new SqlParameter("AS_IN", xml),
						new SqlParameter("AS_OUT", SqlDbType.VarChar, 1024 ), //输出参数
					};
                para[0].Direction = ParameterDirection.Input;
                para[1].Direction = ParameterDirection.Output;
                return new SqlHelper().f_saveTable(ap_set, ProName, para);
            }
            catch (Exception)
            {

                throw;
            }

        }


        /// <summary>
        /// 返回DataSet数据集
        /// </summary>
        /// <param name="proName">存储过程名字</param>
        /// <returns></returns>
        public DataSet TableSelect(string proName, string xml)
        {

            try
            {
                SqlHelper sqlhelper = new SqlHelper();
                SqlParameter[] para = new SqlParameter[]
					{
						new SqlParameter("AS_IN", xml),
						new SqlParameter("AS_OUT", SqlDbType.VarChar, 1024 ), //输出参数
					};
                DataSet table = new DataSet();
                para[0].Direction = ParameterDirection.Input;
                para[1].Direction = ParameterDirection.Output;
                return table = sqlhelper.RunProcDataSet(proName, para);
            }
            catch (Exception)
            {

                throw;
            }

        }

    }
}
